from selenium.webdriver import Chrome
import time

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.select import Select

webdriver = Chrome(executable_path="D:\driver\chromedriver.exe")
webdriver.get("https://www.douban.com/")
# time.sleep(5)
# # items = webdriver.find_elements_by_class_name("item")
# items = webdriver.find_elements_by_xpath("//*[@id = 'content']/div/div[2]/div[3]/div[3]/div/div[1]/div/div[2]/a[@class='item']")
# for item in items:
#     assert isinstance(item, WebElement)
#     # print(item.tag_name, item.get_attribute("class"))
#     file_name = item.find_element_by_tag_name("p")
#     rate = item.find_element_by_xpath("p/strong")
#     print(file_name.text, rate)
search_input = webdriver.find_element_by_xpath('//*[@id="anony-nav"]/div[2]/form/span[1]/input')
# search_input = webdriver.find_element_by_xpath('//*[@id="anony-nav"]/div[1]/ul/li[2]/a')
# assert isinstance(search_input, WebElement)
# search_input.send_keys("电影")
# search_input.click()
# search_input.submit()

# search_input.send_keys("电影xxx")
# time.sleep(1)
# search_input.send_keys(Keys.BACK_SPACE)
# search_input.send_keys(Keys.BACK_SPACE)
# search_input.send_keys(Keys.BACK_SPACE)
# search_input.submit()
# time.sleep(5)

# select 标签
# method 1
# webdriver.get("url")
# select = webdriver.find_elements_by_xpath("xpath")
# assert isinstance(select, WebElement)
# options = select.find_elements_by_tag_name('options')
# options[2].click()
#
# # method 2
# select = Select(webdriver.get('select xpath'))
# select.select_by_visible_text('text value')

# 前进
webdriver.forward()

# 后退
webdriver.back()

# 窗口对象
webdriver.window_handles()




# method 3
select = Select(webdriver.get('select xpath'))
# select.select_by_index(2)
select.select_by_value('options value')

webdriver.close()



